package cn.evilelf.sort;

class SortUtil {

	static int[] swap(int[] array, int m, int n) {
		int temp = array[m];
		array[m] = array[n];
		array[n] = temp;

		return array;
	}

	static long[] swap(long[] array, int m, int n) {
		long temp = array[m];
		array[m] = array[n];
		array[n] = temp;

		return array;
	}

	static float[] swap(float[] array, int m, int n) {
		float temp = array[m];
		array[m] = array[n];
		array[n] = temp;

		return array;
	}

	static double[] swap(double[] array, int m, int n) {
		double temp = array[m];
		array[m] = array[n];
		array[n] = temp;

		return array;
	}

	@SuppressWarnings("unchecked")
	static Comparable[] swap(Comparable[] array, int m, int n) {
		Comparable temp = array[m];
		array[m] = array[n];
		array[n] = temp;

		return array;
	}

	static int[] reverse(int[] array) {
		for (int left = 0, right = array.length - 1; left < right; left++, right--) {
			swap(array, left, right);
		}

		return array;
	}

	static long[] reverse(long[] array) {
		for (int left = 0, right = array.length - 1; left < right; left++, right--) {
			swap(array, left, right);
		}

		return array;
	}

	static float[] reverse(float[] array) {
		for (int left = 0, right = array.length - 1; left < right; left++, right--) {
			swap(array, left, right);
		}

		return array;
	}

	static double[] reverse(double[] array) {
		for (int left = 0, right = array.length - 1; left < right; left++, right--) {
			swap(array, left, right);
		}

		return array;
	}

	@SuppressWarnings("unchecked")
	static Comparable[] reverse(Comparable[] array) {
		for (int left = 0, right = array.length - 1; left < right; left++, right--) {
			swap(array, left, right);
		}

		return array;
	}
}
